Attribute VB_Name = "modFileHandling"
Public Sub WriteINI(ByVal cSection As String, cKey As String, cValue As String, cPath As String)
  cPath = App.Path & "\" & cPath
  
  WritePrivateProfileString cSection, cKey, cValue, cPath
End Sub

Public Function ReadINI(ByVal cSection As String, cKey As String, cPath As String) As String
  Dim cBuff As String, cLen As Long
  
  
  cPath = App.Path & "\" & cPath
  cBuff = String(255, vbNull)
  cLen = GetPrivateProfileString(cSection, cKey, Chr(0), cBuff, 255, cPath)
  
  If cLen > 0 Then
    ReadINI = cBuff
  Else
    Select Case LCase(cKey)
      Case "greet status", "idle status"
        ReadINI = 0
        Exit Function
    End Select
  
    ReadINI = vbNullString
  End If
End Function

Public Sub writeUser(ByVal WriteString As String)
  Set userFSO = CreateObject("Scripting.FileSystemObject")
  
  If Not userFSO.FileExists(App.Path & "\" & "Users.txt") Then
    userFSO.CreateTextFile (App.Path & "\" & "Users.txt")
    AddChat vbGray, "-- Created ", vbGreen, "Users.txt"
    frmStatus.txtMainWindowAddChat.Caption = frmStatus.txtMainWindowAddChat.Caption + 1
    
  End If
  
  Set writeUsers = userFSO.GetFile(App.Path & "\" & "Users.txt").OpenAsTextStream(8)
  writeUsers.writeLine WriteString
  writeUsers.Close
End Sub

Function WriteChannels(appname As String, key As String, sstring As String) As Boolean
Dim sFile As String
Dim l As Long
WriteChannels = False
On Error GoTo writechannels_Error
sFile = App.Path & "\QuickChannels.txt"
l = WritePrivateProfileString(appname, key, sstring, sFile)
WriteChannels = True

writechannels_Error:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Function

Function ReadChannels(appname As String, key As String) As String
Dim sFile As String
Dim sDefault As String
Dim lSize As Integer
Dim l As Long
Dim sUser As String
sUser = Space$(128)
lSize = Len(sUser)
sFile = App.Path & "\QuickChannels.txt"
sDefault = ""
l = GetPrivateProfileString(appname, key, sDefault, sUser, lSize, sFile)
sUser = Mid(sUser, 1, InStr(sUser, Chr(0)) - 1)
ReadChannels = sUser
End Function

Function WriteProfile(appname As String, key As String, sstring As String) As Boolean
Dim sFile As String
Dim l As Long
WriteProfile = False
On Error GoTo writeprofile_Error
sFile = App.Path & "\Profile.ini"
l = WritePrivateProfileString(appname, key, sstring, sFile)
WriteProfile = True

writeprofile_Error:
If Err.Number <> 0 Then
MsgBox Err.Description
End If
End Function

Function ReadProfile(appname As String, key As String) As String
Dim sFile As String
Dim sDefault As String
Dim lSize As Integer
Dim l As Long
Dim sUser As String
sUser = Space$(128)
lSize = Len(sUser)
sFile = App.Path & "\Profile.ini"
sDefault = ""
l = GetPrivateProfileString(appname, key, sDefault, sUser, lSize, sFile)
sUser = Mid(sUser, 1, InStr(sUser, Chr(0)) - 1)
ReadProfile = sUser
End Function
